package com.hex.liyue.usermodule.activity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.hex.liyue.R;
import com.hex.liyue.commonmodule.activity.BaseActivity;
import com.hex.liyue.commonmodule.manager.UserManager;
import com.hex.liyue.commonmodule.utils.StatusBarCompatUtils;
import com.hex.liyue.commonmodule.utils.ValuesUtils;
import com.hex.liyue.commonmodule.view.IosChoiceDialog;
import com.hex.liyue.usermodule.presenter.ISetingView;
import com.hex.liyue.usermodule.presenter.SettingPresenter;

import butterknife.Bind;
import butterknife.OnClick;

/**
 * 这是一个设置界面
 * Created by yukoyuan on 16/6/14.
 */
public class SettingActivity extends BaseActivity implements ISetingView {
    @Bind(R.id.iv_toobar_back)
    ImageView ivToobarBack;
    @Bind(R.id.tv_toobar_title)
    TextView tvToobarTitle;
    @Bind(R.id.tv_setting_exit_login)
    TextView tvSettingExitLogin;
    @Bind(R.id.tv_service_tel)
    TextView tvServiceTel;

    private SettingPresenter settingPresenter;
    private Intent intent;

    @Override
    protected void bindPresenter() {
        settingPresenter = new SettingPresenter(this);
    }

    @Override
    protected void initData(Bundle extras) {
        tvSettingExitLogin.setText(ValuesUtils.getString(R.string.exitlogin) + "(" + UserManager.getNickName() + ")");
    }

    @Override
    public int getContentLayout() {
        return R.layout.activity_setting;
    }

    @Override
    protected void initToolbar() {
        StatusBarCompatUtils.compat(this);
        ivToobarBack.setVisibility(View.VISIBLE);
        tvToobarTitle.setVisibility(View.VISIBLE);
        tvToobarTitle.setText("设置");
    }


    @OnClick({R.id.iv_toobar_back, R.id.rl_setting_reset_pwd, R.id.rl_setting_feedback,
            R.id.rl_setting_customer_phone, R.id.tv_setting_exit_login})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.iv_toobar_back:
                onBackPressed();
                break;
            case R.id.rl_setting_reset_pwd:
                startResetPwdActivity();
                break;
            case R.id.rl_setting_feedback:
                startFeedBackActivity();
                break;
            case R.id.rl_setting_customer_phone:
                startCallTel();
                break;
            case R.id.tv_setting_exit_login:
                exitLogin();
                break;
        }
    }

    /**
     * 弹出对话框,并退出登录
     */
    private void exitLogin() {
        IosChoiceDialog iosChoiceDialog = new IosChoiceDialog(this, "提醒", "确定要退出登录?");
        iosChoiceDialog.setOnButtonClickListener(new IosChoiceDialog.OnButtonClickListener() {
            @Override
            public void onOkClickListener() {
                settingPresenter.exitLogin();

            }

            @Override
            public void onCancelClickListener() {

            }
        });
        iosChoiceDialog.show();
    }

    @Override
    public void showLod(String msg) {
        showLoad(this, msg);
    }

    @Override
    public void closeLod() {
        closeLoad();
    }

    @Override
    public void showT(String msg) {
        showToast(this, msg);
    }

    @Override
    public void startLoginAndRegistActivity() {
        intent = new Intent(this, LoginAndRegistActivity.class);
        startActivity(intent);
    }

    @Override
    public void startFeedBackActivity() {
        intent = new Intent(this, FeedBackActivity.class);
        startActivity(intent);
    }

    @Override
    public void startResetPwdActivity() {
        intent = new Intent(this, UpdatePwdActivity.class);
        startActivity(intent);
    }

    @Override
    public void startCallTel() {
//        String message="确认呼叫 "+tvServiceTel.getText().toString()+" 吗？";
//        IosChoiceDialog iosChoiceDialog=new IosChoiceDialog(this,"系统提示",message);
//        iosChoiceDialog.setOnButtonClickListener(new IosChoiceDialog.OnButtonClickListener() {
//            @Override
//            public void onOkClickListener() {
        intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + tvServiceTel.getText().toString()));
        startActivity(intent);
//            }
//
//            @Override
//            public void onCancelClickListener() {
//
//            }
//        });
//        iosChoiceDialog.show();
    }

}
